package com.memg.config;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;

// 4.定义一个Servlet容器的启动配置类，在里面加载SpringMvcConfig的配置
public class ServletContainersInitConfig extends AbstractDispatcherServletInitializer {

    // 创建Servlet容器，并加载SpringMvcConfig的配置
    @Override
    protected WebApplicationContext createServletApplicationContext() {
        AnnotationConfigWebApplicationContext  ctx = new AnnotationConfigWebApplicationContext();
        ctx.register(SpringMvcConfig.class);
        return ctx;
    }

    // 设置哪些请求归属SpringMvc处理
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }


    // 加载Spring容器，并设置SpringMvcConfig的配置
    @Override
    protected WebApplicationContext createRootApplicationContext() {
        return null;
    }
}

